#include "SqlStringMap.h"
#include "SingleToolDefine.h"
#include <map>
#include <QString>
namespace tools
{
	MapString gMapString;
	int initData()
	{
		gMapString[PersonPostion1] = "select top 201 * from worksitepass where cardnum = 13001";
		gMapString[PersonPostion2] = "select top 201 * from worksitepass where cardnum = 13002";
		gMapString[PersonPostion3] = "select top 201 * from worksitepass where cardnum = 13003";
		gMapString[PersonPostion4] = "select top 201 * from worksitepass where cardnum = 13004";
		gMapString[PersonPostion5] = "select top 201 * from worksitepass where cardnum = 13005";

		gMapString[personPath1] = "begin set nocount on exec [up_CoordinatesPointPersonHistoryInfo] 13001,3,'2013-03-25 17:39:29.000','2013-06-19 17:39:29.00' end";
		gMapString[personPath2] = "begin set nocount on exec [up_CoordinatesPointPersonHistoryInfo] 13002,3,'2013-03-25 17:39:29.000','2013-06-19 17:39:29.00' end";
		gMapString[personPath3] = "begin set nocount on exec [up_CoordinatesPointPersonHistoryInfo] 13003,3,'2013-03-25 17:39:29.000','2013-06-19 17:39:29.00' end";
		gMapString[personPath4] = "begin set nocount on exec [up_CoordinatesPointPersonHistoryInfo] 13004,3,'2013-03-25 17:39:29.000','2013-06-19 17:39:29.00' end";

		gMapString[worksiteCvsFile] = "select * from worksite";
		gMapString[rtPersonlistCvsFile] = "";
		gMapString[Askforhelpcvsfile] = "select * from askforhelp";
		gMapString[Arealarmcvsfile] = "select * from areaalarm";

		gMapString[articlesCvsfile] = "select * from articles";
		gMapString[articlesstatusCvsfile] = "select * from articlesstatus";
		gMapString[articlestypeCvsfile] = "select * from articlestype";
		gMapString[departmentCvsfile] = "select * from department";

		gMapString[goodshistoryinfo1] = "begin set nocount on exec [up_CoordinatesPointGoodsHistoryInfo] 13003, 4, '2013-05-1 15:03:24.000','2013-05-4 15:03:24.000' end";
		gMapString[goodshistoryinfo1] = "begin set nocount on exec [up_CoordinatesPointGoodsHistoryInfo] 13003, 4, '2013-05-1 15:03:24.000','2013-05-4 15:03:24.000' end";


		gMapString[personinforCvsFile] = "select top 50 cl.cardNum,p.personName,p.departmentId,d.parentId as departParentId,d.name,p.officePositionId,op.name,cl.worksiteid,cl.x,cl.y,cl.z,occTime,\
										 sex,p.mobile,p.telephone,inTime,outTime,a.id as areaId,a.aName,a.Type,a.isAllow,a.outSpanTime,d.parentId,p.personNo\
										 from CardLoc cl inner join person p on p.cardNumber = cl.cardNum and cl.CardType = 3\
										 inner join dbo.corAreaWorksite cow on cow.worksiteid= cl.worksiteid inner join area a on a.id=cow.areaId\
										 left outer join department d on d.id = p.departmentId left outer join \
										 classTeam ct on p.classTeamId = ct.id  left outer join \
										 officePosition op on op.id = p.officePositionId";
		gMapString[corareaworksiteCvsfile] = "select * from corareaworksite";
		gMapString[goodsinforCvsfile] = "select cl.cardNum,a.Name,d.id,d.name,at.name as GoodsType,a.tag,convert(varchar(23),a.registerTime,120),\
										cl.worksiteid,cl.x,cl.y,cl.z,cl.occTime,area.id as areaId,area.aName,area.Type,area.isAllow,area.outSpanTime,area.parentId,ci.Status\
										from CardLoc cl\
										inner join Articles a on a.cardNumber = cl.cardNum and cl.CardType = 4 \
										inner join dbo.corAreaWorksite cow on cow.worksiteid= cl.worksiteid inner join area on area.id=cow.areaId\
										inner join cardInformation ci on ci.cardNum=cl.cardNum and ci.CardType=cl.CardType \
										left outer join department d on d.id = a.departmentId \
										left outer join ArticlesType at on at.id=a.type";
		gMapString[cardSosCvsfile] = "select * from cardsos";
		gMapString[historypersonCvsfile] = "select * from historyperson";
		gMapString[areaovertimealarmCvsfile] = "select * from areaovertimealarm";

		gMapString[areaCvsfile] = "select * from area;";
		gMapString[corareaworksiteCvsFile] = "select * from corareaworksite";
		gMapString[officepositionstateCvsFile] = "select * from officeposition";
		gMapString[areatypeCvsFile] = "select * from areatype";
		return 0;
	}

	std::string getFileName( const std::string& str )
	{
		std::string fileName;
		int pos = str.find_last_of("\\");
		if (pos != -1)
		{
			fileName = str.substr(pos+1, str.size() - 1);
		}
		return fileName;
	}

	QString getFileName( const QString& str )
	{
		QString fileName;
		int pos = str.lastIndexOf("\\");
		if (pos != -1)
		{
			fileName = str.right(str.size() - pos -1);
		}
		return fileName;
	}

	const std::string& getSqlString( const std::string& fileName )
	{
		std::string str = "..\\Resource\\csv\\";
		str += fileName;
		MapString::iterator it = gMapString.find(str);
		if (it != gMapString.end())
		{
			return it->second;
		}
		static std::string empty;
		return empty;
	}

}